<script>
	function checkImageExt(obj) {
		var t = obj.value;
		var txt = obj.value.substring(obj.value.lastIndexOf(".")+1).toLowerCase();
		if(!(txt == "jpg" || txt == "jpeg" || txt == "gif" || txt == "png" )) {
			alert("ไฟล์รูปภาพที่แนบมาไม่ถูกต้อง " + t + "\nกรุณาเลือกไฟล์ใหม่");	
		}
	}
	function vailadte() {
		if(document.getElementById('txtDetail').value == '') {
			document.getElementById('txtDetail').focus();
			alert('กรุณาใส่รายละเอียดผลงาน');
			return false;
		}
		return true;
			
	}
</script>
<div id="mainContent">
	<form  name="myForm" id="myForm" enctype="multipart/form-data" method="post" action="<?=site_url()?>StudentHallOfFame/saveInFrame" onsubmit="return vailadte();">
		<input name="txtId" type="hidden" id="txtId" value="<?php if(isset($stu_id)) echo $stu_id; ?>"/> 
		<table width="800px" align="center" cellpadding="2" cellspacing="2" style="border: 1px solid #0000FF; background-color: #FFFFFF">
		  <col width="170px" />
		  <col width="*" />
		  <tr bgcolor="#000974">
		    <td colspan="2" align="left" bgcolor="#000974" style="color:#FFFFFF;"><label>.:: Hall of Fame ในกรอบ</label></td>
		  </tr>
		  <tr>
		    <td align="right"><label>รายละเอียดผลงาน</label><span class="require">*</span></td>
		    <td align="left">
		      <textarea name="txtDetail" id="txtDetail" rows="15" cols="65"><?php if(isset($detail)) echo $detail; ?></textarea> <br/>   
		 	</td>
		  </tr>
		  <tr>
		  	<td align="right" valign="top"><label>ไฟล์รูปภาพ</label></td>
		    <td align="left"><input name="imageUpload" type="file" id="imageUpload" size="25" onchange="checkImageExt(this);" /> 
		    </td>
		  </tr>
		  <tr>
		    <td align="right">&nbsp;</td>
		    <td align="left"><input type="submit" name="button" id="button" value="บันทึกข้อมูล" /> 
		       <input type="submit" name="button4" id="button4" value="ลบข้อมูล" onclick="setTargetForm('delete');"/></td>
		  </tr>
		  <tr style="height:10px;">
		    <td colspan="2"></td>
		  </tr>
		</table>
	</form>
</div>
<script type="text/javascript">
	function setTargetForm(val) {
		var frm = document.forms["myForm"];
		frm.action = "<?=site_url()?>StudentHallOfFame/delete";
		frm.submit();
	}
</script>
